1
|
|
|
import React, { Component } from "react"; |
2
|
|
|
import ReactDOM from "react-dom"; |
3
|
|
|
import classNames from "classnames"; |
4
|
|
|
|
5
|
|
|
export default class Reference extends Component { |
6
|
|
|
constructor(props) { |
7
|
|
|
super(props); |
8
|
|
|
this.state = { |
9
|
|
|
active: false, |
10
|
|
|
name: props.initName, |
11
|
|
|
}; |
12
|
|
|
this.handleTriggerClick = this.handleTriggerClick.bind(this); |
13
|
|
|
this.handleNameChange = this.handleNameChange.bind(this); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
handleTriggerClick() { |
17
|
|
|
console.log("click"); |
18
|
|
|
this.setState(state => ({ |
19
|
|
|
active: !state.active, |
20
|
|
|
})); |
21
|
|
|
// this.setState({active: !this.state.active}); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
handleNameChange(event) { |
25
|
|
|
this.setState({ |
26
|
|
|
name: event.target.value, |
27
|
|
|
}); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
componentDidCatch(error, info) { |
31
|
|
|
console.log(error); |
32
|
|
|
console.log(info); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
render() { |
36
|
|
|
const triggerClass = classNames( |
37
|
|
|
"profile-element", |
38
|
|
|
"accordion", |
39
|
|
|
"reference", |
40
|
|
|
"modal-target-object", |
41
|
|
|
{ active: this.state.active }, |
42
|
|
|
); |
43
|
|
|
return ( |
44
|
|
|
<div className={triggerClass}> |
45
|
|
|
<button |
46
|
|
|
aria-expanded={this.state.active} |
47
|
|
|
className="accordion-trigger" |
48
|
|
|
tabIndex="0" |
49
|
|
|
type="button" |
50
|
|
|
onClick={this.handleTriggerClick} |
51
|
|
|
> |
52
|
|
|
{this.props.showStatus && ( |
53
|
|
|
<div className="accordion-status"> |
54
|
|
|
<i className="fas fa-check" /> |
55
|
|
|
<i className="fas fa-exclamation-circle" /> |
56
|
|
|
</div> |
57
|
|
|
)} |
58
|
|
|
<span className="accordion-title">{this.props.title}</span> |
59
|
|
|
</button> |
60
|
|
|
|
61
|
|
|
<div aria-hidden={!this.state.active} className="accordion-content"> |
62
|
|
|
<form action={this.props.url} method="POST"> |
63
|
|
|
<div className="form__wrapper"> |
64
|
|
|
<div className="form-error box" /> |
65
|
|
|
<div className="flex-grid"> |
66
|
|
|
<div className="box med-1of2"> |
67
|
|
|
<div |
68
|
|
|
className={classNames("form__input- wrapper--float", { |
69
|
|
|
active: this.state.name, |
70
|
|
|
})} |
71
|
|
|
> |
72
|
|
|
<label |
73
|
|
|
className="form__label" |
74
|
|
|
htmlFor={`referenceName${this.props.id}`} |
75
|
|
|
> |
76
|
|
|
{this.props.lang.name_label} |
77
|
|
|
</label> |
78
|
|
|
<input |
79
|
|
|
className="form__input" |
80
|
|
|
id={`referenceName${this.props.id}`} |
81
|
|
|
type="text" |
82
|
|
|
name="name" |
83
|
|
|
required |
84
|
|
|
value={this.state.name} |
85
|
|
|
onChange={this.handleNameChange} |
86
|
|
|
/> |
87
|
|
|
</div> |
88
|
|
|
</div> |
89
|
|
|
</div> |
90
|
|
|
</div> |
91
|
|
|
</form> |
92
|
|
|
</div> |
93
|
|
|
</div> |
94
|
|
|
); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
if (document.getElementById("react-reference")) { |
99
|
|
|
ReactDOM.render( |
100
|
|
|
<Reference key="1" id="1" url="/" initName="Joe Bob" locale="profile" />, |
101
|
|
|
document.getElementById("react-reference"), |
102
|
|
|
); |
103
|
|
|
} |
104
|
|
|
|